from django.db import models
import datetime


class Event(models.Model):
    month = models.ForeignKey('service.Month', on_delete=models.CASCADE, related_name='events')
    kind = models.TextField(choices=[
        ('work_time', 'work_time'),
        ('time_off', 'time_off'),
        ('sick', 'sick'),
        ('vacation', 'vacation'),
        ('work_delta', 'work_delta'),
    ])
    day = models.IntegerField()
    user = models.ForeignKey('users.User', on_delete=models.CASCADE, related_name='events', null=True, blank=True)
    start_time = models.TimeField()
    end_time = models.TimeField()
    viewed = models.BooleanField(default=False)

    @property
    def date(self):
        return datetime.date(self.month.year, self.month.month, self.day)

    class Meta:
        db_table = "event"
